home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / b_calc_files.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  26.0 KB  |  1,042 lines  |  [TEXT/KAHL]

  1. /*    look at this    */
  2.  
  3.             /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
  4.             /*                                                               */
  5.             /*                    Prototype HP15C Calculator                */
  6.             /*                    James C. Ullrey                            */
  7.             /*                    INRESCO                                    */
  8.             /*                    © 1990                                    */
  9.             /*                    Version    13.97a                            */
  10.             /*                                                               */
  11.             /*                    FILE SEGMENT                               */
  12.             /*                                                               */
  13.             /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
  14.  
  15.  
  16.  
  17. /*****************************************************************/
  18. /*  I N C L U D E S                                                 */
  19. /*****************************************************************/
  20.  
  21. #include "TE32K.h"
  22. #ifndef __C14__
  23. #include    "C14 Calculator.h"
  24. #endif
  25. #include "Globals.h"
  26. #include "calc_matrix_functions.h"
  27. #include <Lists.h>
  28. #include "C14CalculatorData.h"
  29. #include "calc_files.h"
  30. #include "ResourceDefs.h"
  31. #include  "calc_dipshit.h"
  32.  
  33.  
  34. /********************************************************************
  35. /*  G L O B A L   V A R I A B L E   D E C L A R A T I O N S
  36. /********************************************************************/
  37. extern    Boolean        newCreated;
  38. extern    Boolean        preRegistered;
  39. extern    WindowPtr    gMy_windows[];
  40. extern    long        gState;
  41. extern    long        gsState;
  42. extern    long         sto;
  43. extern    long         rcl;
  44. /*extern    long     gNewNum;*/
  45. /*extern    long     canClear;*/
  46. /*extern    long     gRoll;*/
  47. extern    long         wait;
  48. extern    long         gFlag;
  49. extern    long         fFlag;
  50. extern    long         sWait;
  51. extern    long         rWait;
  52. extern    long         lblWait;
  53. extern    long         plus;
  54. extern    long         minus;
  55. extern    long         timesF;
  56. extern    long         divide;
  57. extern    long         gDot;
  58. /*extern    long     rsFlag;*/
  59. extern    long    gDigits;
  60. /*extern    long    runMode;*/
  61. /*extern    long    gsbWait;*/
  62. extern    long        gtoWait;
  63. extern    short        qRefNum;
  64. extern    short        pRefNum;
  65. extern    short        SRcount;
  66. extern    Boolean        hasPlot;
  67.  
  68. /*****************************************************************/
  69. /*  P R O T O T Y P E S
  70. /*****************************************************************/
  71.     ListHandle    CreateList            (    WindowPtr    theWindow,
  72.                                         short        rowInt,
  73.                                         short        colInt);
  74.  
  75.         void    IndexDeparse        (    short        i);
  76.         short    do_save_file         (WindowPtr wPtr, short do_sfput);
  77.  
  78.         void     close_the_window    (WindowPtr wPtr);
  79.                                         
  80.         OSErr    get_c_filespec        (short wd_refnum, long *dir_id, short *vol_refnum);
  81.  
  82. /*****************************************************************/
  83. /*****************************************************************/
  84. /*
  85. /* R O U T I N E S
  86. /*
  87. /*****************************************************************/
  88. /*****************************************************************/
  89.  
  90.  
  91. void    file_seg() {}        /*  for reference in "UnloadSeg()" calls    */
  92.  
  93.  
  94. /********************** SetUpFile ************************/
  95. //void SetUpFile( fn, prn, refNum )                                /* called from main()    */
  96. void SetUpFile( Str255    *fn, Str255    *prn, short        *refNum )    /* called from main()    */
  97. //Str255        *fn;        /* data filename     */
  98. //Str255        *prn;        /* program filename    */
  99. //short        *refNum;    /* Volume ID (or working dir) of open System file */
  100. {
  101.     short            io;
  102.     short            i;
  103.     short            notDone = 1;
  104.     long            count,fcount;
  105.     Str255            sresult;
  106.     SFReply         reply;
  107.     OSErr             error;
  108.  
  109.     /*newCreated = FALSE;*/
  110.     count = sizeof(map);
  111.     while(notDone)
  112.     {
  113.         error = FSOpen(*fn, *refNum,&qRefNum);                /* II-91, IV-109    */
  114.         if(error == fnfErr || error == bdNamErr)
  115.         {    
  116.             error = Create( *fn, *refNum, 'INRS', 'INRC');    /* II-90, IV-112    */
  117.             error = FSOpen(*fn, *refNum,&qRefNum);
  118.             /*newCreated = TRUE;*/
  119.             InitMapData(fn,*refNum,qRefNum);        /* in C14CalculatorData.c */
  120.         }
  121.         else
  122.         {
  123.             error = SetFPos(qRefNum,1,0);                    /* II-93, IV-110    */
  124.             error = FSRead(qRefNum,&count,&map);            /* II-92, IV-109    */
  125.             if(map.regstat == 0 && map.memstat == 0)
  126.             {
  127.                 map.memstat = 19;
  128.                 map.regstat = 65 - map.memstat - map.memcom;
  129.             }
  130.         }
  131.         /*error = FSClose(qRefNum);*/                        /* II-94, IV-112    */
  132.         if(!error)
  133.             notDone = 0;
  134.     }
  135.     notDone = 1;
  136.     fcount = sizeof(frog);
  137.     while(notDone)
  138.     {
  139.         /*                |-------------------------------- file name        */
  140.         /*                |        |------------------------ dir ref no    */
  141.         /*                |        |            |------------ file ref no    */
  142.         /*                v        v            v                            */
  143.         error = FSOpen(*prn, *refNum, &pRefNum);                /* II-91, IV-109    */
  144.         if(error == fnfErr || error == bdNamErr)
  145.         {    
  146.             error = Create( *prn, *refNum, 'INRS', 'INRP');    /* II-90, IV-112    */
  147.             frog.PC = 0;
  148.             frog.tPC = 0;
  149.             frog.SP = 0;
  150.             frog.END = 1;
  151.             frog.breakout = 0x0000;
  152.             SRcount = 0;
  153.  
  154.         }
  155.         else
  156.         {
  157.             /*                                                                        */
  158.             /*                        |--    1: from start; 2: from end; 3: from mark    */
  159.             /*                        | |------ offset                                */
  160.             /*                        v v                                                */
  161.             error = SetFPos(pRefNum,1,0);                    /* II-93, IV-110    */
  162.             error = FSRead(pRefNum,&fcount,&frog);            /* II-92, IV-109    */
  163.         }
  164.         /*error = FSClose(qRefNum);*/                        /* II-94, IV-112    */
  165.         if(!error)
  166.             notDone = 0;
  167.     }
  168. }
  169.  
  170. void    save_window(WindowPtr wPtr)
  171. {
  172.     short        user_response = 0;
  173.     char        w_title[255];
  174.     WObjsHandle    w_objs_hndl;
  175.     short        the_object;
  176.  
  177.  
  178. /***
  179.     First, check if the window pointer is a valid one for the application.
  180.     If so, check to see if the window has been written to but not saved.
  181. ***/        
  182.  
  183.  
  184.     if(!one_of_mine(wPtr)) return;
  185.  
  186.     w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);    
  187.     if(w_objs_hndl == NIL) return;
  188.     
  189.         /*w_objs_hndl=(WObjs**)GetWRefCon(wPtr);*/
  190.     the_object = (**w_objs_hndl).paletteSetting;
  191.  
  192.  
  193.     if(the_object == PLOT_OBJ)
  194.     {
  195.         hasPlot = FALSE;    /*    reset hasPlot    */
  196.         /*DeleteMenu( PLOT_MENU_ID );*/
  197.         DeleteMenu( PlotID );
  198.         DrawMenuBar();
  199.     }
  200.  
  201.  
  202.  
  203.     if((**w_objs_hndl).dirty)
  204.     {
  205.         GetWTitle(wPtr, (StringPtr)w_title);
  206.         ParamText((StringPtr)w_title, "\p", "\p", "\p");
  207.             
  208.         #ifdef      powerc
  209.             user_response = CautionAlert(SAVE_CHANGES, (UniversalProcPtr)NIL);
  210.         #else
  211.             user_response = CautionAlert(SAVE_CHANGES, NIL);
  212.         #endif      /* powerc */
  213.                         
  214.         switch(user_response)
  215.         {
  216.             case SAVE_YES:
  217.                 #ifdef      powerc
  218.                     StopAlert (UNDER_CONSTRUCTION, (UniversalProcPtr)NIL);
  219.                 #else
  220.                     StopAlert (UNDER_CONSTRUCTION,    NIL);
  221.                 #endif      /* powerc */    
  222.                 if(do_save_file(wPtr, DO_SAVE) == SUCCESS)
  223.                         close_the_window(wPtr);
  224.                 else
  225.                         gDone = FALSE;
  226.                 break;
  227.                 
  228.             case SAVE_NO:
  229.                 close_the_window(wPtr);
  230.                 break;
  231.                 
  232.             case SAVE_CANCEL:
  233.                 gDone = false;       /* if "Cancel", stop any "quit" operation */
  234.                 break;
  235.                 
  236.         }  /*  end of switch    */
  237.         
  238.     }  /*  end of if(**w_objs_hndl).dirty)    */
  239.     
  240.     
  241.     else close_the_window(wPtr);
  242.                     
  243.                                     
  244. }  /*  end of "save_window()"    */
  245.  
  246.  
  247. void    close_the_window(WindowPtr wPtr)
  248. {
  249.     short        n;
  250.     WObjsHandle    w_objs_hndl;
  251.  
  252.     
  253.  
  254. /*************    If it isn't one of our windows, skip it!    ******************/
  255.  
  256.  
  257.     if( !(n = one_of_mine(wPtr)) ) return;
  258.  
  259.     
  260.  
  261. /*****    Else dispose the controls and window, and clear our list    **********/
  262.  
  263.  
  264.     w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
  265.     if(w_objs_hndl != NIL)
  266.     {
  267.         HLock((Handle)w_objs_hndl);
  268.         /*    look at this    */
  269.         if((**w_objs_hndl).prInfoHndl)    DisposHandle((Handle)(**w_objs_hndl).prInfoHndl);
  270.         DisposHandle((Handle)w_objs_hndl);
  271.     }
  272.     
  273.     DisposeWindow(gMy_windows[n]);    /*  also does a "KillControls()"    */
  274.     
  275.     gMy_windows[n] = NIL;
  276.  
  277.  
  278. }  /*  end of close_the_window()    */
  279.  
  280.  
  281. short    do_save_file(WindowPtr wPtr,short do_what)
  282. //WindowPtr wPtr;
  283. //short    do_what;
  284.  
  285. {
  286.     short        file_ref_num, wd_refnum, vol_refnum;
  287.     Point        where;
  288.     long        count, dir_id;
  289.     OSErr        error_code;
  290.     OSType        the_creator, our_type;
  291.     char        local_str[256], window_name[256];
  292.     char        *srce_ptr, *dest_ptr;
  293.     char        **dlog_str_hndl;
  294.     Ptr            data_ptr;
  295.     WObjsHandle    w_objs_hndl;
  296.     THPrint        pr_info_hndl;
  297.  
  298.     
  299.  
  300. /*********    If our window data structure is absent, don't even start this!    **********/
  301.  
  302.  
  303.     w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
  304.     
  305.     if(w_objs_hndl == NIL) return(FILE_ERROR);
  306.  
  307.     
  308.  
  309. /*************    Set up some initial values and lock our window data         **********/
  310.  
  311.  
  312.     count = 0;
  313.     the_creator = CREATOR_CODE;        /*  our "creator type"                    */
  314.     our_type    = TYPE_CODE;        /*  our "file type"                        */
  315.     SetPt(&where, 100, 80);            /*  where to put the file dialog boxes    */
  316.     
  317.     MoveHHi((Handle)w_objs_hndl);
  318.     HLock ((Handle)w_objs_hndl);
  319.  
  320.  
  321. /**
  322.     Note:
  323.     
  324.     The "findFile" element of the window data structure is of type SFReply.
  325.     The structure of the SFReply record is as follows:
  326.             
  327.             typedef struct
  328.             {
  329.                 Boolean        good;
  330.                 Boolean        copy;
  331.                 fType        OSType;
  332.                 short        vrefNum;
  333.                 short        version;
  334.                 char        fName[255];
  335.             }SFReply;
  336. **/
  337.     
  338.  
  339. /*********    Build up the dialog prompt: "Save (filename) as:"    **********/
  340.  
  341. /**    
  342.     Use strings save in 'STR " resources named "Save" and "As", 
  343.     and the file name from the "findFile" item in the window info record.
  344. **/
  345.  
  346.     
  347.     local_str[0] = 0;
  348.     dest_ptr = local_str;
  349.     
  350.     dlog_str_hndl = (char**)GetString(SAVE_ID);
  351.     MoveHHi(dlog_str_hndl);
  352.     HLock  (dlog_str_hndl);
  353.     
  354.         srce_ptr = (char*)*dlog_str_hndl;
  355.         cat_strings(srce_ptr, dest_ptr, 255);
  356.         
  357.     HUnlock(dlog_str_hndl);
  358.  
  359.     GetWTitle(wPtr, (StringPtr)window_name);
  360.     
  361.     srce_ptr = window_name;        
  362.     cat_strings(srce_ptr, dest_ptr, 255);
  363.  
  364.     
  365.     dlog_str_hndl = (char**)GetString(AS_ID);
  366.     MoveHHi(dlog_str_hndl);
  367.     HLock  (dlog_str_hndl);
  368.     
  369.         srce_ptr = (char*)*dlog_str_hndl;
  370.         cat_strings(srce_ptr, dest_ptr, 255);
  371.         
  372.     HUnlock(dlog_str_hndl);
  373.  
  374.     
  375.  
  376. /***
  377.     If we need to specify a file name, do SFPut thing...
  378. ***/
  379.  
  380.  
  381.     if( (do_what == DO_SFPUT) ||
  382.         ((**w_objs_hndl).hasRealName == FALSE) )
  383.     {
  384.         InitCursor();
  385.         #ifdef powerc 
  386.             SFPutFile(    where,
  387.                         (StringPtr)local_str,
  388.                         (StringPtr)window_name,
  389.                         (UniversalProcPtr)NIL,
  390.                         &(**w_objs_hndl).findFile);
  391.         #else
  392.             SFPutFile(    where,
  393.                         (StringPtr)local_str,
  394.                         (StringPtr)window_name,
  395.                         NIL,
  396.                         &(**w_objs_hndl).findFile);
  397.         #endif
  398. /***
  399.     If the user cancelled the operation, restore the window name
  400. ***/
  401.         
  402.         if ((**w_objs_hndl).findFile.good == FALSE)
  403.         {
  404.             dest_ptr = (char*)((**w_objs_hndl).findFile.fName);
  405.             (**w_objs_hndl).findFile.fName[0] = 0;
  406.             cat_strings(window_name, dest_ptr, 255);
  407.             
  408.             HUnlock((Handle)w_objs_hndl);
  409.             return(CANCELED);
  410.         }
  411.         
  412.  
  413. /***
  414.     Otherwise, get the vol_refnum and create the file
  415. ***/
  416.  
  417.         else
  418.         {
  419.             wd_refnum = (**w_objs_hndl).findFile.vRefNum;
  420.     
  421.             error_code = get_c_filespec(wd_refnum, &dir_id, &vol_refnum);
  422.             if(error_code != noErr) return(FILE_ERROR);
  423.  
  424.             error_code = Create(
  425.                             (**w_objs_hndl).findFile.fName,
  426.                             wd_refnum,
  427.                             the_creator,
  428.                             our_type);
  429.                             
  430.             if( (error_code != noErr) && 
  431.                 (error_code != dupFNErr) )
  432.             {
  433.                 #ifdef      powerc
  434.                     StopAlert(CREATE_ERR, (UniversalProcPtr)NIL);
  435.                 #else
  436.                     StopAlert(CREATE_ERR,    NIL);
  437.                 #endif      /* powerc */                
  438.                 HUnlock((Handle)w_objs_hndl);
  439.                 return(CREATE_ERR);
  440.             }
  441.             else  (**w_objs_hndl).hasRealName = TRUE;
  442.         }
  443.     }
  444.  
  445.     
  446.  
  447. /*************    Save the data in the specified file                            **********/
  448.  
  449.  
  450. /***    a)  open the file    ***/
  451.  
  452.     if( (do_what == DO_SFPUT) ||
  453.         (do_what == DO_SAVE) ) 
  454.     {
  455.         wd_refnum = (**w_objs_hndl).findFile.vRefNum;
  456.     
  457.         error_code = get_c_filespec(wd_refnum, &dir_id, &vol_refnum);
  458.         if(error_code != noErr) return(FILE_ERROR);
  459.  
  460.         error_code = FSOpen(
  461.                         (**w_objs_hndl).findFile.fName,
  462.                         wd_refnum,
  463.                         &file_ref_num);
  464.     
  465.         if    ((error_code != noErr) || (file_ref_num == 0) )
  466.         {
  467.             StopAlert(OPEN_ERR,0);
  468.             HUnlock((Handle)w_objs_hndl);
  469.             return(CANCELED);
  470.         }
  471.     
  472.  
  473.  
  474. /***    b)  check to see that there's disc space    ***/
  475.  
  476.         count = sizeof(fileDataRecord);
  477.         error_code = SetEOF(file_ref_num, count);
  478.  
  479.         if    (error_code != noErr)
  480.         {
  481.             StopAlert(WRITE_ERR,0);
  482.             HUnlock((Handle)w_objs_hndl);
  483.             return(CANCELED);
  484.         }
  485.     
  486.     
  487.  
  488.  
  489. /*************    c)  write the data to the file                **********/
  490.  
  491. /***
  492.     Note:    we are only writing that portion of the WObjs Record 
  493.             that includes the object-count and the objects themselves.
  494.             We have intentionally positioned these items together at 
  495.             the end (bottom) of the definition of the WObjsRecord.  
  496.             
  497.             Thus, by pointing to (**w_objs_hndl).vDocLimit and
  498.             supplying a byte count equal to the size of this portion 
  499.             of the data structure, we can write just the data we want 
  500.             to the file without having to gather it together from 
  501.             separate places into a single block before writing.
  502. ***/
  503.  
  504. /***
  505.     Note:    before writing the data out, copy the print info record from
  506.             the heap into the window objects record.
  507. ***/
  508.  
  509.         //pr_info_hndl = (**w_objs_hndl).prInfoHndl;
  510.         //(**w_objs_hndl).printInfo = **pr_info_hndl;
  511.  
  512.  
  513.         data_ptr = (Ptr)(&(**w_objs_hndl).vDocLimit);
  514.         
  515.         error_code = FSWrite(file_ref_num, &count, data_ptr);
  516.         if    (error_code != noErr)
  517.         {
  518.             StopAlert(WRITE_ERR,0);
  519.             HUnlock((Handle)w_objs_hndl);
  520.             return(CANCELED);
  521.         }
  522.  
  523.  
  524. /*********    d)  close the file                                **********/
  525.  
  526.  
  527.         error_code = FSClose(file_ref_num);
  528.         
  529.         if    (error_code != noErr)
  530.         {
  531.             StopAlert(WRITE_ERR,0);
  532.             HUnlock((Handle)w_objs_hndl);
  533.             return(CANCELED);
  534.         }
  535.  
  536.  
  537. /*************    e)  post the data to the disc                **********/
  538.  
  539.         error_code = FlushVol(0, vol_refnum);
  540.         
  541.         if    (error_code != noErr)
  542.         {
  543.             StopAlert(WRITE_ERR,0);
  544.             HUnlock((Handle)w_objs_hndl);
  545.             return(CANCELED);
  546.         }
  547.  
  548.     }  /*  end of  do_what = SFPUT || do_what == DO_SAVE    */
  549.  
  550.  
  551.  
  552. /***
  553.     we made it!
  554. ***/
  555.  
  556.  
  557.     HUnlock((Handle)w_objs_hndl);
  558.  
  559.     (**w_objs_hndl).dirty = FALSE;
  560.     
  561.     return(SUCCESS);
  562.     
  563. }  /*  end of  do_save_file()    */
  564.  
  565. OSErr get_c_filespec(short wd_refnum,long *dir_id,short *vol_refnum)
  566.  
  567. {
  568.    WDPBRec pb_rec;
  569.    OSErr   err;
  570.  
  571.  
  572.    pb_rec.ioNamePtr  = NIL;
  573.    pb_rec.ioWDProcID = 0L;
  574.    pb_rec.ioWDIndex  = 0;
  575.    pb_rec.ioVRefNum  = wd_refnum;
  576.    
  577.    err = PBGetWDInfo(&pb_rec, FALSE);
  578.    
  579.    if(err == noErr)
  580.    {
  581.         *dir_id     = pb_rec.ioWDDirID;
  582.         *vol_refnum = pb_rec.ioWDVRefNum;
  583.    }
  584.    
  585.    return(err);
  586. }
  587.  
  588.  
  589.  
  590. /********************* RestoreMatLists **********************/
  591. void    RestoreMatLists(void)
  592. {
  593.     short        i,j;
  594.     short        rowInt,colInt,howMuch,matFirstReg;
  595.     WindowPtr    theWindow;
  596.     Rect        rView;
  597.     Rect        rDataBnds;
  598.     Point        cellSize;
  599.     short        procID;
  600.     Boolean        drawIt,hasGrow,scrollHoriz,scrollVert;
  601.     Ptr            dataPtr;
  602.     Cell        theCell;
  603.     short        dataLen;
  604.     short        fxLen,flLen;
  605.  
  606.     for( i = 1; i <= 5; i++)
  607.     {
  608.         switch(i)
  609.         {
  610.             case    1:
  611.                 matFirstReg = map.matA.firstreg;
  612.                 if( matFirstReg != 70)
  613.                 {
  614.                     theWindow = gMatAWindow;
  615.                     rowInt = map.matA.row;
  616.                     colInt = map.matA.col;
  617.                     matAList = CreateList(theWindow,rowInt,colInt);
  618.                     howMuch = rowInt * colInt;
  619.                     for( j = matFirstReg; j > matFirstReg - howMuch; j--)
  620.                     {
  621.                         ResultDeParse(map.reg[j].real,&fxLen,&flLen);
  622.                         if(gF.style == 0)        dataLen = flLen;
  623.                         else if(gF.style == 1)    dataLen = fxLen;
  624.                         //dataLen = gResultString[0];
  625.                         theCell.v = (matFirstReg - j) / colInt;
  626.                         theCell.h = (matFirstReg - j) % colInt;
  627.                         LSetCell(&gResultString[0],dataLen,theCell,matAList);
  628.                     }
  629.                 }
  630.                 break;
  631.             case 2:
  632.                 matFirstReg = map.matB.firstreg;
  633.                 if( matFirstReg != 70)
  634.                 {    
  635.                     theWindow = gMatBWindow;
  636.                     rowInt = map.matB.row;
  637.                     colInt = map.matB.col;
  638.                     matBList = CreateList(theWindow,rowInt,colInt);
  639.                     howMuch = rowInt * colInt;
  640.                     for( j = matFirstReg; j > matFirstReg - howMuch; j--)
  641.                     {
  642.                         ResultDeParse(map.reg[j].real,&fxLen,&flLen);
  643.                         if(gF.style == 0)        dataLen = flLen;
  644.                         else if(gF.style == 1)    dataLen = fxLen;
  645.                         //dataLen = gResultString[0];
  646.                         theCell.v = (matFirstReg - j) / colInt;
  647.                         theCell.h = (matFirstReg - j) % colInt;
  648.                         LSetCell(&gResultString[0],dataLen,theCell,matBList);
  649.                     }
  650.                 }
  651.                 break;
  652.             case 3:
  653.                 matFirstReg = map.matC.firstreg;
  654.                 if( matFirstReg != 70)
  655.                 {
  656.                     theWindow = gMatCWindow;
  657.                     rowInt = map.matC.row;
  658.                     colInt = map.matC.col;
  659.                     matCList = CreateList(theWindow,rowInt,colInt);
  660.                     howMuch = rowInt * colInt;
  661.                     for( j = matFirstReg; j > matFirstReg - howMuch; j--)
  662.                     {
  663.                         ResultDeParse(map.reg[j].real,&fxLen,&flLen);
  664.                         if(gF.style == 0)        dataLen = flLen;
  665.                         else if(gF.style == 1)    dataLen = fxLen;
  666.                         //dataLen = gResultString[0];
  667.                         theCell.v = (matFirstReg - j) / colInt;
  668.                         theCell.h = (matFirstReg - j) % colInt;
  669.                         LSetCell(&gResultString[0],dataLen,theCell,matCList);
  670.                     }
  671.                 }
  672.                 break;
  673.             case 4:
  674.                 matFirstReg = map.matD.firstreg;
  675.                 if( matFirstReg != 70)
  676.                 {
  677.                     theWindow = gMatDWindow;
  678.                     rowInt = map.matD.row;
  679.                     colInt = map.matD.col;
  680.                     matDList = CreateList(theWindow,rowInt,colInt);
  681.                     howMuch = rowInt * colInt;
  682.                     for( j = matFirstReg; j > matFirstReg - howMuch; j--)
  683.                     {
  684.                         ResultDeParse(map.reg[j].real,&fxLen,&flLen);
  685.                         if(gF.style == 0)        dataLen = flLen;
  686.                         else if(gF.style == 1)    dataLen = fxLen;
  687.                         //dataLen = gResultString[0];
  688.                         theCell.v = (matFirstReg - j) / colInt;
  689.                         theCell.h = (matFirstReg - j) % colInt;
  690.                         LSetCell(&gResultString[0],dataLen,theCell,matDList);
  691.                     }
  692.                 }
  693.                 break;
  694.             case 5:
  695.                 matFirstReg = map.matE.firstreg;
  696.                 if( matFirstReg != 70)
  697.                 {
  698.                     theWindow = gMatEWindow;
  699.                     rowInt = map.matE.row;
  700.                     colInt = map.matE.col;
  701.                     matEList = CreateList(theWindow,rowInt,colInt);
  702.                     howMuch = rowInt * colInt;
  703.                     for( j = matFirstReg; j > matFirstReg - howMuch; j--)
  704.                     {
  705.                         ResultDeParse(map.reg[j].real,&fxLen,&flLen);
  706.                         if(gF.style == 0)        dataLen = flLen;
  707.                         else if(gF.style == 1)    dataLen = fxLen;
  708.                         //dataLen = gResultString[0];
  709.                         theCell.v = (matFirstReg - j) / colInt;
  710.                         theCell.h = (matFirstReg - j) % colInt;
  711.                         LSetCell(&gResultString[0],dataLen,theCell,matEList);
  712.                     }
  713.                 }
  714.                 break;
  715.         }
  716.     }
  717. }
  718. /********************* RestoreRegLists **********************/
  719. void    RestoreRegLists(void)
  720. {
  721.     WindowPtr    theWindow;
  722.     Point        nCellSize;
  723.     Point        dCellSize;
  724.     short        range,range2;
  725.     Rect        r1nView;
  726.     Rect        r1dView;
  727.     Rect        r1nDataBnds;
  728.     Rect        r1dDataBnds;
  729.     Rect        r2nView;
  730.     Rect        r2dView;
  731.     Rect        r2nDataBnds;
  732.     Rect        r2dDataBnds;
  733.     Rect        r3nView;
  734.     Rect        r3dView;
  735.     Rect        r3nDataBnds;
  736.     Rect        r3dDataBnds;
  737.     Rect        r4nView;
  738.     Rect        r4dView;
  739.     Rect        r4nDataBnds;
  740.     Rect        r4dDataBnds;
  741.     Cell        theCell;
  742.     short        nDataLen;
  743.     short        dDataLen;
  744.     short        i,dataLen;
  745.     short        fxLen,flLen;
  746.     
  747.     /******** work site ********/
  748.     theWindow = gSRegWindow;
  749.     nCellSize.h = 20;
  750.     nCellSize.v = 10;
  751.     dCellSize.h = 80;
  752.     dCellSize.v = nCellSize.v;
  753.     if(map.memcom <= 20)
  754.         SizeWindow(theWindow,nCellSize.h + dCellSize.h,map.memcom * nCellSize.v,TRUE);
  755.     else if (map.memcom > 20 && map.memcom <= 40)
  756.         SizeWindow(theWindow,2 * nCellSize.h + 2 * dCellSize.h,20 * nCellSize.v,TRUE);
  757.     else if (map.memcom > 40 && map.memcom <= 60)
  758.         SizeWindow(theWindow,3 * (nCellSize.h + dCellSize.h) + 1,20 * nCellSize.v,TRUE);
  759.     else if (map.memcom > 60)
  760.         SizeWindow(theWindow,4 * (nCellSize.h + dCellSize.h) + 1,20 * nCellSize.v,TRUE);
  761.  
  762.     if(map.memcom <= 20)
  763.     {
  764.         range = 65 - map.memcom;
  765.         SetRect(&r1nView,0,0,nCellSize.h,map.memcom * nCellSize.v);
  766.         SetRect(&r1dView,nCellSize.h + 1,0,nCellSize.h + dCellSize.h + 1,map.memcom * nCellSize.v);
  767.         SetRect(&r1nDataBnds,0,0,1,map.memcom);
  768.         SetRect(&r1dDataBnds,0,0,1,map.memcom);
  769. /*        SizeWindow(theWindow,nCellSize.h + dCellSize.h,map.memcom * nCellSize.v,TRUE);*/
  770.     }
  771.     else
  772.     {
  773.         range = 65 - 20;
  774.         SetRect(&r1nView,0,0,nCellSize.h,20 * nCellSize.v);
  775.         SetRect(&r1dView,nCellSize.h + 1,0,nCellSize.h + dCellSize.h + 1,20 * nCellSize.v);
  776.         SetRect(&r1nDataBnds,0,0,1,20);
  777.         SetRect(&r1dDataBnds,0,0,1,20);
  778.     }
  779.     /*if(!SRegListn1)*/
  780.         SRegListn1 = LNew(    &r1nView,
  781.                         &r1nDataBnds,    /*     (0,0,0,0)    */
  782.                         nCellSize,        /*    (0,0)(0,0)    */
  783.                         0,                /*    procID        */
  784.                         theWindow,
  785.                         1,                /*    drawIt        */
  786.                         0,                /*    hasGrow        */
  787.                         0,                /*    scrollHoriz    */
  788.                         0                /*    scrollVert    */
  789.                     );
  790.     /*if(!SRegListd1)*/
  791.         SRegListd1 = LNew(    &r1dView,
  792.                         &r1dDataBnds,    /*     (0,0,0,0)    */
  793.                         dCellSize,        /*    (0,0)(0,0)    */
  794.                         0,                /*    procID        */
  795.                         theWindow,
  796.                         1,                /*    drawIt        */
  797.                         0,                /*    hasGrow        */
  798.                         0,                /*    scrollHoriz    */
  799.                         0                /*    scrollVert    */
  800.                     );
  801.     theCell.h = 0;
  802.     nDataLen = 2;
  803.     for(i = 65; i > range; i--)
  804.     {
  805.         IndexDeparse(i);
  806.         theCell.v = 65 - i;
  807.         LSetCell(&gIndexString[0],nDataLen,theCell,SRegListn1);
  808.         ResultDeParse(map.reg[i].real,&fxLen,&flLen);
  809.         if(gF.style == 0)        dDataLen = flLen;
  810.         else if(gF.style == 1)    dDataLen = fxLen;
  811.         //dDataLen = gResultString[0];
  812.         LSetCell(&gResultString[0],dDataLen,theCell,SRegListd1);
  813.     }
  814.     
  815.     
  816.     /*if(map.memcom > 20 && map.memcom <= 40)*/
  817.     if(map.memcom > 20)                            /*    range = 65 - map.memcom;    */
  818.     {
  819.         SetRect(&r2nView,nCellSize.h + dCellSize.h + 1,0,2 * nCellSize.h + dCellSize.h,20 * nCellSize.v);
  820.         SetRect(&r2dView,2 * nCellSize.h + dCellSize.h + 1,0,2 * nCellSize.h + 2 * dCellSize.h,20 * nCellSize.v);
  821.         SetRect(&r2nDataBnds,0,0,1,map.memcom);
  822.         SetRect(&r2dDataBnds,0,0,1,map.memcom);
  823. /*        SizeWindow(theWindow,2 * nCellSize.h + 2 * dCellSize.h,20 * nCellSize.v,TRUE);*/
  824.         SRegListn2 = LNew(    &r2nView,
  825.                             &r2nDataBnds,    /*     (0,0,0,0)    */
  826.                             nCellSize,        /*    (0,0)(0,0)    */
  827.                             0,                /*    procID        */
  828.                             theWindow,
  829.                             1,                /*    drawIt        */
  830.                             0,                /*    hasGrow        */
  831.                             0,                /*    scrollHoriz    */
  832.                             0                /*    scrollVert    */
  833.                         );
  834.         SRegListd2 = LNew(    &r2dView,
  835.                             &r2dDataBnds,    /*     (0,0,0,0)    */
  836.                             dCellSize,        /*    (0,0)(0,0)    */
  837.                             0,                /*    procID        */
  838.                             theWindow,
  839.                             1,                /*    drawIt        */
  840.                             0,                /*    hasGrow        */
  841.                             0,                /*    scrollHoriz    */
  842.                             0                /*    scrollVert    */
  843.                         );
  844.         if(map.memcom > 20 && map.memcom < 40)
  845.         {
  846.             range2 = 65 - map.memcom;
  847.         }
  848.         else
  849.         {
  850.             range2 = 25;
  851.         }
  852.         for(i = 45; i > range2; i--)
  853.         {
  854.             IndexDeparse(i);
  855.             theCell.v = 45 - i;
  856.             LSetCell(&gIndexString[0],nDataLen,theCell,SRegListn2);
  857.             ResultDeParse(map.reg[i].real,&fxLen,&flLen);
  858.             if(gF.style == 0)        dDataLen = flLen;
  859.             else if(gF.style == 1)    dDataLen = fxLen;
  860.             //dDataLen = gResultString[0];
  861.             LSetCell(&gResultString[0],dDataLen,theCell,SRegListd2);
  862.         }
  863.     }
  864.     /*if(map.memcom > 40 && map.memcom <= 60)*/
  865.     if(map.memcom > 40)
  866.     {
  867.         SetRect(&r3nView,2 * (nCellSize.h + dCellSize.h) + 1,0,3 * nCellSize.h + 2 * dCellSize.h,20 * nCellSize.v);
  868.  
  869.         SetRect(&r3dView,3 * nCellSize.h + 2 * dCellSize.h + 1,0,3 * (nCellSize.h + dCellSize.h) + 1,20 * nCellSize.v);
  870.  
  871.         SetRect(&r3nDataBnds,0,0,1,map.memcom);
  872.         SetRect(&r3dDataBnds,0,0,1,map.memcom);
  873. /*        SizeWindow(theWindow,3 * (nCellSize.h + dCellSize.h) + 1,20 * nCellSize.v,TRUE);*/
  874.         SRegListn3 = LNew(    &r3nView,
  875.                             &r3nDataBnds,        /* (0,0,0,0)    */
  876.                             nCellSize,        /*    (0,0)(0,0)    */
  877.                             0,                /*    procID        */
  878.                             theWindow,
  879.                             1,                /*    drawIt        */
  880.                             0,                /*    hasGrow        */
  881.                             0,                /*    scrollHoriz    */
  882.                             0                /*    scrollVert    */
  883.                         );
  884.         SRegListd3 = LNew(    &r3dView,
  885.                             &r3dDataBnds,        /* (0,0,0,0)    */
  886.                             dCellSize,        /*    (0,0)(0,0)    */
  887.                             0,                /*    procID        */
  888.                             theWindow,
  889.                             1,                /*    drawIt        */
  890.                             0,                /*    hasGrow        */
  891.                             0,                /*    scrollHoriz    */
  892.                             0                /*    scrollVert    */
  893.                         );
  894.         if(map.memcom > 40 && map.memcom < 60)
  895.         {
  896.             range2 = 65 - map.memcom;
  897.         }
  898.         else
  899.         {
  900.             range2 = 5;
  901.         }
  902.         for(i = 25; i > range2; i--)
  903.         {
  904.             IndexDeparse(i);
  905.             theCell.v = 25 - i;
  906.             LSetCell(&gIndexString[0],nDataLen,theCell,SRegListn3);
  907.             ResultDeParse(map.reg[i].real,&fxLen,&flLen);
  908.             if(gF.style == 0)        dDataLen = flLen;
  909.             else if(gF.style == 1)    dDataLen = fxLen;
  910.             //dDataLen = gResultString[0];
  911.             LSetCell(&gResultString[0],dDataLen,theCell,SRegListd3);
  912.         }
  913.     }
  914.     if(map.memcom > 60)
  915.     {
  916.         SetRect(&r4nView,3 * (nCellSize.h + dCellSize.h) + 1,0,4 * nCellSize.h + 3 * dCellSize.h + 1,20 * nCellSize.v);
  917.  
  918.         SetRect(&r4dView,4 * nCellSize.h + 3 * dCellSize.h + 1,0,4 * (nCellSize.h + dCellSize.h) + 1,20 * nCellSize.v);
  919.  
  920.         SetRect(&r4nDataBnds,0,0,1,map.memcom);
  921.         SetRect(&r4dDataBnds,0,0,1,map.memcom);
  922. /*        SizeWindow(theWindow,4 * (nCellSize.h + dCellSize.h) + 1,20 * nCellSize.v,TRUE);*/
  923.         SRegListn4 = LNew(    &r4nView,
  924.                             &r4nDataBnds,        /* (0,0,0,0)    */
  925.                             nCellSize,        /*    (0,0)(0,0)    */
  926.                             0,                /*    procID        */
  927.                             theWindow,
  928.                             1,                /*    drawIt        */
  929.                             0,                /*    hasGrow        */
  930.                             0,                /*    scrollHoriz    */
  931.                             0                /*    scrollVert    */
  932.                         );
  933.         SRegListd4 = LNew(    &r4dView,
  934.                             &r4dDataBnds,        /* (0,0,0,0)    */
  935.                             dCellSize,        /*    (0,0)(0,0)    */
  936.                             0,                /*    procID        */
  937.                             theWindow,
  938.                             1,                /*    drawIt        */
  939.                             0,                /*    hasGrow        */
  940.                             0,                /*    scrollHoriz    */
  941.                             0                /*    scrollVert    */
  942.                         );
  943.         for(i = 5; i > 65 - map.memcom; i--)
  944.         {
  945.             IndexDeparse(i);
  946.             theCell.v = 5 - i;
  947.             LSetCell(&gIndexString[0],nDataLen,theCell,SRegListn4);
  948.             ResultDeParse(map.reg[i].real,&fxLen,&flLen);
  949.             if(gF.style == 0)        dDataLen = flLen;
  950.             else if(gF.style == 1)    dDataLen = fxLen;
  951.             //dDataLen = gResultString[0];
  952.             LSetCell(&gResultString[0],dDataLen,theCell,SRegListd4);
  953.         }
  954.  
  955.     
  956.     }
  957.     if(preRegistered) DipShit();
  958.     
  959. }
  960. /********************* IndexDeparse **********************/
  961. void    IndexDeparse(short i)    /* this is used at launch time to read register values into the    */
  962. //short    i;                        /* registers list    */
  963. {
  964.     decimal        result;
  965.     double_t    temp;
  966.     Str255        sresult;
  967.     
  968.     gF.style = 1;                                /*1 is for fixed point*/
  969.     gF.digits = 2;    /*10 - (log(map.stk1.real))/(log(10));*/    /*    Fixed point        */
  970.     temp = i;
  971.     num2dec(&gF,temp,&result);
  972.     //x96tox80(&temp,&result);
  973.     //num2str( &gF, result, &gIndexString );
  974.     //num2str( &gF, temp, &gIndexString );
  975.     //sprintf(gIndexString,"%f",temp);
  976.     dec2str(&gF,&result,gIndexString);
  977. }
  978.  
  979. /********************** CreateList ***********************/
  980. ListHandle    CreateList(WindowPtr theWindow,short rowInt,short colInt)
  981. //WindowPtr    theWindow;
  982. //short        rowInt;
  983. //short        colInt;
  984. {
  985.     ListHandle    theList;
  986.     Rect        rView;
  987.     Rect        rDataBnds;
  988.     Point        cellSize;
  989.     short        procID;
  990.     Boolean        drawIt,hasGrow,scrollHoriz,scrollVert;
  991.     Ptr            dataPtr;
  992.     
  993.     //SetRect(&rView,0,0,colInt*100,rowInt*15);
  994.     SetRect(&rView,0,0,colInt*120,rowInt*15);
  995.     SetRect(&rDataBnds,0,0,colInt,rowInt);
  996.     cellSize.h = 80;
  997.     //cellSize.h = 100;
  998.     cellSize.v = 10;
  999.     theList = LNew(    &rView,
  1000.                         &rDataBnds,        /* (0,0,0,0)    the rect is cells, not pixels*/
  1001.                         cellSize,        /*    (0,0)(0,0)    */
  1002.                         0,                /*    procID        */
  1003.                         theWindow,
  1004.                         1,                /*    drawIt        */
  1005.                         0,                /*    hasGrow        */
  1006.                         0,                /*    scrollHoriz    */
  1007.                         0                /*    scrollVert    */
  1008.                     );
  1009.     SizeWindow( theWindow,colInt*80,rowInt*10,TRUE);
  1010.     //SizeWindow( theWindow,colInt*100,rowInt*10,TRUE);
  1011.     return    theList;
  1012. }
  1013.  
  1014. /*********************** FillList ************************/
  1015.  
  1016. /*    from where is this called?    */    /* <------look at this!    */
  1017.  
  1018. //void    FillList(short rowInt,short colInt,WindowPtr theWindow,short matFirstReg)
  1019. //short        rowInt;
  1020. //short        colInt;
  1021. //WindowPtr    theWindow;
  1022. //short        matFirstReg;
  1023. //{
  1024. //    ListHandle    theList;
  1025. //    short        j,howMuch;
  1026. //    Cell        theCell;
  1027. //    short        dataLen;
  1028. //    short        fxLen,flLen;
  1029.  
  1030. //    howMuch = rowInt * colInt;
  1031. //    for( j = matFirstReg; j >= howMuch; j--)
  1032. //    {
  1033. //        ResultDeParse(map.reg[j].real,&fxLen,&flLen);
  1034. //        if(gF.style == 0)        dataLen = flLen;
  1035. //        else if(gF.style == 1)    dataLen = fxLen;
  1036. //        //dataLen = gResultString[0];
  1037. //        theCell.v = (matFirstReg - j) / colInt;
  1038. //        theCell.h = (matFirstReg - j) % colInt;
  1039. //        LSetCell(&gResultString[0],dataLen,theCell,theList);
  1040. //    }
  1041. //}
  1042.